package leetcode.code0452;

import java.util.Arrays;

import leetcode.IDebug;
import leetcode.helper.HelpDebug;

public class Solution implements IDebug {

	public int findMinArrowShots(int[][] points) {
		Arrays.sort(points, (a, b) -> a[0] - b[0]);
		int ans = 0;
		int l = -1;
		int r = -1;
		for (int[] point : points) {
			int a = point[0];
			int b = point[1];
			if ((a >= l && a <= r) || (b >= l && b <= r)) {
				l = Math.max(a, l);
				r = Math.min(b, r);
			} else {
				l = a;
				r = b;
				ans++;
			}
		}
		return ans;
	}

	@Override
	public void debug1() {
		HelpDebug.compare(2, this.findMinArrowShots(HelpDebug.str2array1("[[10,16],[2,8],[1,6],[7,12]]")));

	}

	@Override
	public void debug2() {

		HelpDebug.compare(4, this.findMinArrowShots(HelpDebug.str2array1("[[1,2],[3,4],[5,6],[7,8]]")));

	}

	@Override
	public void debug3() {

		HelpDebug.compare(2, this.findMinArrowShots(HelpDebug.str2array1("[[1,2],[2,3],[3,4],[4,5]]")));

	}

	@Override
	public void debug4() {

		HelpDebug.compare(1, this.findMinArrowShots(HelpDebug.str2array1("[[2,3],[2,3]]")));

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
